//
//  MineViewController.swift
//  GuMro
//
//  Created by mac on 2019/12/4.
//  Copyright © 2019 cn.gomro.app. All rights reserved.
//

import UIKit

/** 我的 */
class MineViewController: BaseViewController {

    
    //MARK: - override
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
     
    override func updateViewConstraints() {
        
        self.mainView.snp.makeConstraints { make in
            make.left.right.equalTo(0)
            make.top.equalTo(K_APP_NAVIGATION_BAR_HEIGHT)
            make.bottom.equalTo(-K_APP_TABBAR_HEIGHT)
        }
        
        super.updateViewConstraints()
    }

    /** 添加视图 */
    override func addSubViews() {
        self.view.addSubview(self.mainView)
        self.view.backgroundColor = UIColor.init().colorFromHexString(hex:"#F0F1F4")
    }
    
    /** 设置导航 */
    override func layoutNavigation() {
       //MARK:导航
       self.initNavgationBar(isBottomLine: false,
                             isShadow: false)
       
       //MARK:标题
       self.initViewControllerTitle(strTitle: "个人中心")
    }
    
    /** 绑定事件 */
    override func bindViewModel() {
        
        //列点击
        self.viewModel.cellDidSelect.take(until: self.rac_willDeallocSignal())?.subscribeNext({ (input:Any?) in
//            guard let menu = input as? String else { return }
            
//            switch(menu){
//                case "客服中心":
//                    SVProgressHUD.showInfo(withStatus: "敬请期待")
//                
//                case "意见反馈":
//                    let avc = AdviceViewController.init()
//                    self.navigationController?.pushViewController(avc, animated: true)
//
//                case "关于我们":
//                    let c = AboutViewController.init()
//                    self.navigationController?.pushViewController(c, animated: true)
//                
//                case "我的台账":
//                    let c = LedgerListViewController.init()
//                    self.navigationController?.pushViewController(c, animated: true)
//                
//                case "地图中心":
//                    let vc = MapViewController.init()
//                    self.navigationController?.pushViewController(vc, animated: true)
//                
//                case "清除缓存":
//                    let strSize:String = Utils.shareInstance().getAppCacheSize()
//                    let _size:Float = NSString.init(string: strSize.replacingOccurrences(of: "M", with: "")).floatValue
//                    if _size <= Float.init(0) {
//                        SVProgressHUD.showInfo(withStatus:"没有缓存无需清理哦")
//                        return
//                    }
//
//                let isOk = Utils.shareInstance().clearnAppCache()
//                if isOk {
//                    SVProgressHUD.showInfo(withStatus:"缓存清理完毕")
//                    self.mainView.listTableView.reloadData()
//                }
//
//                default:
//                    SVProgressHUD.showInfo(withStatus: menu)
//                    break
//            }
        })
        
        //查看用户信息
        self.viewModel.showUserInfo.take(until: self.rac_willDeallocSignal())?.subscribeNext({ (input:Any?) in
            SVProgressHUD.showInfo(withStatus: "查看用户信息")
        })
        
        //登录
        self.viewModel.gotoLogin.take(until: self.rac_willDeallocSignal())?.subscribeNext({[weak self] (input:Any?) in
            guard let self = self else { return }
            
            if !UserModel.userIsLogined {
               self.toLogin(Finish: nil)
            }
            else{
               print("已登录无需操作")
            }
        })
    }
    
    /** 获取新数据 */
    override func getNewData() {
        if UserModel.userIsLogined {
            self.mainView.mineHead.labName.text = UserModel.userName
            self.mainView.mineHead.labCompany.text = UserModel.userOrgIzaName
        }
        else{
            self.mainView.mineHead.labName.text = "请登录"
            self.mainView.mineHead.labCompany.text = "xxx股份有限公司"
        }
    }
        
     
    //MARK: - lazy load
    private lazy var mainView:MineView = {
        autoreleasepool {
            let _mv = MineView.init(ViewModel: self.viewModel)
            return _mv
        }
    }()

    private lazy var viewModel:MineViewModel = {
        let _vm = MineViewModel()
        return _vm
    }()
}
